package com.example.rbacmanage.controller.background;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.app.MinAppConfig;
import com.example.rbacmanage.service.app.MinAppConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/background/minappconfig")
public class MinAppConfigController {
    @Autowired
    private MinAppConfigService minAppConfigService;

    @GetMapping("/page")
    public Result page(MinAppConfig minAppConfig){
        return Result.success(minAppConfigService.getPage(minAppConfig));
    }

    @GetMapping("/{id}")
    public Result info(@PathVariable Long id){
        return Result.success(minAppConfigService.getById(id));
    }

    @PreAuthorize("hasAnyAuthority('background:minappconfig:add')")
    @PostMapping("/add")
    public Result add(@RequestBody MinAppConfig minAppConfig){
        minAppConfigService.save(minAppConfig);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('background:minappconfig:update')")
    @PutMapping("/update")
    public Result update(@RequestBody MinAppConfig minAppConfig){
        minAppConfigService.update(minAppConfig);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('background:minappconfig:remove')")
    @DeleteMapping("/remove")
    public Result remove(@RequestBody Long[] ids){
        minAppConfigService.remove(ids);
        return Result.success();
    }
}
